/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nms.base;

import com.nms.base.crm.EntityManagerPool;
import com.nms.base.crm.EntityManagerPoolSingleTon;
import com.nms.crm.interfaces.AfterAddInt;
import com.nms.crm.interfaces.BeforAddInt;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

/**
 *
 * @author eisa
 */
public abstract class BaseClass<T> implements BaseInt {

    private EntityManagerPool pool;
    protected List<BeforAddInt> beforAddActions;
    protected List<AfterAddInt> afterAddActions;

    public BaseClass() {
    pool=EntityManagerPoolSingleTon.getInstance();
    }

    

    public Object save(Object obj) {
        
        EntityManager entityManager=null;
        try
        {
          entityManager=  pool.checkOut();
        EntityTransaction entityTransaction= entityManager.getTransaction();
        entityTransaction.begin();
        entityManager.persist(obj);
        entityTransaction.commit();
        }
        finally
        {
            pool.checkIn(entityManager);
        }
        
        return obj;
    }

    public Object update(Object obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Object delete(Object obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
